﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace lcs.DAL
{
	/// <summary>
	/// 数据访问类:supplierinfo
	/// </summary>
	public partial class supplierinfo
	{
		public supplierinfo()
		{}
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("sid", "supplierinfo");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int sid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from supplierinfo");
            strSql.Append(" where sid=@sid");
            SqlParameter[] parameters = {
					new SqlParameter("@sid", SqlDbType.Int,4)
			};
            parameters[0].Value = sid;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(lcs.Model.supplierinfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into supplierinfo(");
            strSql.Append("sno,sname,sadd,slink,sphone,sfax,semail,pslink,psphone,psfax,psemail,ssum)");
            strSql.Append(" values (");
            strSql.Append("@sno,@sname,@sadd,@slink,@sphone,@sfax,@semail,@pslink,@psphone,@psfax,@psemail,@ssum)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@sno", SqlDbType.VarChar,15),
					new SqlParameter("@sname", SqlDbType.NVarChar,30),
					new SqlParameter("@sadd", SqlDbType.NVarChar,90),
					new SqlParameter("@slink", SqlDbType.NVarChar,10),
					new SqlParameter("@sphone", SqlDbType.VarChar,20),
					new SqlParameter("@sfax", SqlDbType.VarChar,15),
					new SqlParameter("@semail", SqlDbType.NVarChar,20),
					new SqlParameter("@pslink", SqlDbType.NVarChar,50),
					new SqlParameter("@psphone", SqlDbType.VarChar,20),
					new SqlParameter("@psfax", SqlDbType.VarChar,15),
					new SqlParameter("@psemail", SqlDbType.NVarChar,20),
                                        new SqlParameter("@ssum", SqlDbType.Int,4)};
            parameters[0].Value = model.sno;
            parameters[1].Value = model.sname;
            parameters[2].Value = model.sadd;
            parameters[3].Value = model.slink;
            parameters[4].Value = model.sphone;
            parameters[5].Value = model.sfax;
            parameters[6].Value = model.semail;
            parameters[7].Value = model.pslink;
            parameters[8].Value = model.psphone;
            parameters[9].Value = model.psfax;
            parameters[10].Value = model.psemail;
            parameters[11].Value = 70;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(lcs.Model.supplierinfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update supplierinfo set ");
            strSql.Append("sno=@sno,");
            strSql.Append("sname=@sname,");
            strSql.Append("sadd=@sadd,");
            strSql.Append("slink=@slink,");
            strSql.Append("sphone=@sphone,");
            strSql.Append("sfax=@sfax,");
            strSql.Append("semail=@semail,");
            strSql.Append("pslink=@pslink,");
            strSql.Append("psphone=@psphone,");
            strSql.Append("psfax=@psfax,");
            strSql.Append("psemail=@psemail,");
            strSql.Append("ssum=@ssum");
            strSql.Append(" where sid=@sid");
            SqlParameter[] parameters = {
					new SqlParameter("@sno", SqlDbType.VarChar,15),
					new SqlParameter("@sname", SqlDbType.NVarChar,30),
					new SqlParameter("@sadd", SqlDbType.NVarChar,90),
					new SqlParameter("@slink", SqlDbType.NVarChar,10),
					new SqlParameter("@sphone", SqlDbType.VarChar,20),
					new SqlParameter("@sfax", SqlDbType.VarChar,15),
					new SqlParameter("@semail", SqlDbType.NVarChar,20),
					new SqlParameter("@pslink", SqlDbType.NVarChar,50),
					new SqlParameter("@psphone", SqlDbType.VarChar,20),
					new SqlParameter("@psfax", SqlDbType.VarChar,15),
					new SqlParameter("@psemail", SqlDbType.NVarChar,20),
                    new SqlParameter("@ssum", SqlDbType.Int,4),
					new SqlParameter("@sid", SqlDbType.Int,4)};
            parameters[0].Value = model.sno;
            parameters[1].Value = model.sname;
            parameters[2].Value = model.sadd;
            parameters[3].Value = model.slink;
            parameters[4].Value = model.sphone;
            parameters[5].Value = model.sfax;
            parameters[6].Value = model.semail;
            parameters[7].Value = model.pslink;
            parameters[8].Value = model.psphone;
            parameters[9].Value = model.psfax;
            parameters[10].Value = model.psemail;
            parameters[11].Value = model.ssum;
            parameters[12].Value = model.sid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool UpdateSum(int sid,int sum)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update supplierinfo set ");            
            strSql.Append("ssum=ssum+@ssum");
            strSql.Append(" where sid=@sid");
            SqlParameter[] parameters = {
					new SqlParameter("@ssum", SqlDbType.Int,4),
                    new SqlParameter("@sid",SqlDbType.Int,4)	};
            parameters[0].Value = sum;
            parameters[1].Value = sid;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int sid)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from supplierinfo ");
            strSql.Append(" where sid=@sid");
            SqlParameter[] parameters = {
					new SqlParameter("@sid", SqlDbType.Int,4)
			};
            parameters[0].Value = sid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string sidlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from supplierinfo ");
            strSql.Append(" where sid in (" + sidlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public lcs.Model.supplierinfo GetModel(int sid)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from supplierinfo ");
            strSql.Append(" where sid=@sid");
            SqlParameter[] parameters = {
					new SqlParameter("@sid", SqlDbType.Int,4)
			};
            parameters[0].Value = sid;

            lcs.Model.supplierinfo model = new lcs.Model.supplierinfo();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["sid"] != null && ds.Tables[0].Rows[0]["sid"].ToString() != "")
                {
                    model.sid = int.Parse(ds.Tables[0].Rows[0]["sid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sno"] != null && ds.Tables[0].Rows[0]["sno"].ToString() != "")
                {
                    model.sno = ds.Tables[0].Rows[0]["sno"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sname"] != null && ds.Tables[0].Rows[0]["sname"].ToString() != "")
                {
                    model.sname = ds.Tables[0].Rows[0]["sname"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sadd"] != null && ds.Tables[0].Rows[0]["sadd"].ToString() != "")
                {
                    model.sadd = ds.Tables[0].Rows[0]["sadd"].ToString();
                }
                if (ds.Tables[0].Rows[0]["slink"] != null && ds.Tables[0].Rows[0]["slink"].ToString() != "")
                {
                    model.slink = ds.Tables[0].Rows[0]["slink"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sphone"] != null && ds.Tables[0].Rows[0]["sphone"].ToString() != "")
                {
                    model.sphone = ds.Tables[0].Rows[0]["sphone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["sfax"] != null && ds.Tables[0].Rows[0]["sfax"].ToString() != "")
                {
                    model.sfax = ds.Tables[0].Rows[0]["sfax"].ToString();
                }
                if (ds.Tables[0].Rows[0]["semail"] != null && ds.Tables[0].Rows[0]["semail"].ToString() != "")
                {
                    model.semail = ds.Tables[0].Rows[0]["semail"].ToString();
                }
                if (ds.Tables[0].Rows[0]["pslink"] != null && ds.Tables[0].Rows[0]["pslink"].ToString() != "")
                {
                    model.pslink = ds.Tables[0].Rows[0]["pslink"].ToString();
                }
                if (ds.Tables[0].Rows[0]["psphone"] != null && ds.Tables[0].Rows[0]["psphone"].ToString() != "")
                {
                    model.psphone = ds.Tables[0].Rows[0]["psphone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["psfax"] != null && ds.Tables[0].Rows[0]["psfax"].ToString() != "")
                {
                    model.psfax = ds.Tables[0].Rows[0]["psfax"].ToString();
                }
                if (ds.Tables[0].Rows[0]["psemail"] != null && ds.Tables[0].Rows[0]["psemail"].ToString() != "")
                {
                    model.psemail = ds.Tables[0].Rows[0]["psemail"].ToString();
                }
                if (ds.Tables[0].Rows[0]["ssum"] != null && ds.Tables[0].Rows[0]["ssum"].ToString() != "")
                {
                    int s=0;
                    int.TryParse(ds.Tables[0].Rows[0]["ssum"].ToString(),out s);
                    model.ssum = s;
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select sid,sno,sname,sadd,slink,sphone,sfax,semail,pslink,psphone,psfax,psemail,ssum ");
            strSql.Append(" FROM supplierinfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet GetList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select sid,sname");
            strSql.Append(" FROM supplierinfo ");            
            return DbHelperSQL.Query(strSql.ToString());
        }
        public DataSet GetListW(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select sid,sname");
            strSql.Append(" FROM supplierinfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" sid,sno,sname,sadd,slink,sphone,sfax,semail,pslink,psphone,psfax,psemail ");
            strSql.Append(" FROM supplierinfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM supplierinfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.sid desc");
            }
            strSql.Append(")AS Row, T.*  from supplierinfo T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "supplierinfo";
            parameters[1].Value = "sid";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
		#region  BasicMethod

        ///// <summary>
        ///// 得到最大ID
        ///// </summary>
        //public int GetMaxId()
        //{
        //return DbHelperSQL.GetMaxID("sid", "supplierinfo"); 
        //}

        ///// <summary>
        ///// 是否存在该记录
        ///// </summary>
        //public bool Exists(int sid)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select count(1) from supplierinfo");
        //    strSql.Append(" where sid=@sid");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@sid", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = sid;

        //    return DbHelperSQL.Exists(strSql.ToString(),parameters);
        //}

        ///// <summary>
        ///// 是否存在该记录,通过供应商和联系人来确定
        ///// </summary>
        //public bool Exists(string sname,string slink)
        //{
        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("select count(1) from supplierinfo");
        //    strSql.Append(" where sname=@sname and slink=@slink ");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@sname", SqlDbType.NVarChar,30),
        //            new SqlParameter("@slink", SqlDbType.NVarChar,10)
        //    };
        //    parameters[0].Value = sname;
        //    parameters[1].Value = slink;

        //    return DbHelperSQL.Exists(strSql.ToString(), parameters);
        //}

        ///// <summary>
        ///// 增加一条数据
        ///// </summary>
        //public int Add(lcs.Model.supplierinfo model)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("insert into supplierinfo(");
        //    strSql.Append("sno,sname,sadd,slink,sphone,sfax,semail)");
        //    strSql.Append(" values (");
        //    strSql.Append("@sno,@sname,@sadd,@slink,@sphone,@sfax,@semail)");
        //    strSql.Append(";select @@IDENTITY");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@sno", SqlDbType.VarChar,15),
        //            new SqlParameter("@sname", SqlDbType.NVarChar,30),
        //            new SqlParameter("@sadd", SqlDbType.NVarChar,90),
        //            new SqlParameter("@slink", SqlDbType.NVarChar,10),
        //            new SqlParameter("@sphone", SqlDbType.VarChar,20),
        //            new SqlParameter("@sfax", SqlDbType.VarChar,15),
        //            new SqlParameter("@semail", SqlDbType.NVarChar,20)};
        //    parameters[0].Value = model.sno;
        //    parameters[1].Value = model.sname;
        //    parameters[2].Value = model.sadd;
        //    parameters[3].Value = model.slink;
        //    parameters[4].Value = model.sphone;
        //    parameters[5].Value = model.sfax;
        //    parameters[6].Value = model.semail;

        //    object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 更新一条数据
        ///// </summary>
        //public bool Update(lcs.Model.supplierinfo model)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("update supplierinfo set ");
        //    strSql.Append("sno=@sno,");
        //    strSql.Append("sname=@sname,");
        //    strSql.Append("sadd=@sadd,");
        //    strSql.Append("slink=@slink,");
        //    strSql.Append("sphone=@sphone,");
        //    strSql.Append("sfax=@sfax,");
        //    strSql.Append("semail=@semail");
        //    strSql.Append(" where sid=@sid");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@sno", SqlDbType.VarChar,15),
        //            new SqlParameter("@sname", SqlDbType.NVarChar,30),
        //            new SqlParameter("@sadd", SqlDbType.NVarChar,90),
        //            new SqlParameter("@slink", SqlDbType.NVarChar,10),
        //            new SqlParameter("@sphone", SqlDbType.VarChar,20),
        //            new SqlParameter("@sfax", SqlDbType.VarChar,15),
        //            new SqlParameter("@semail", SqlDbType.NVarChar,20),
        //            new SqlParameter("@sid", SqlDbType.Int,4)};
        //    parameters[0].Value = model.sno;
        //    parameters[1].Value = model.sname;
        //    parameters[2].Value = model.sadd;
        //    parameters[3].Value = model.slink;
        //    parameters[4].Value = model.sphone;
        //    parameters[5].Value = model.sfax;
        //    parameters[6].Value = model.semail;
        //    parameters[7].Value = model.sid;

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}

        ///// <summary>
        ///// 删除一条数据
        ///// </summary>
        //public bool Delete(int sid)
        //{
			
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("delete from supplierinfo ");
        //    strSql.Append(" where sid=@sid");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@sid", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = sid;

        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}
        ///// <summary>
        ///// 批量删除数据
        ///// </summary>
        //public bool DeleteList(string sidlist )
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("delete from supplierinfo ");
        //    strSql.Append(" where sid in ("+sidlist + ")  ");
        //    int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
        //    if (rows > 0)
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public lcs.Model.supplierinfo GetModel(int sid)
        //{
			
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select  top 1 sid,sno,sname,sadd,slink,sphone,sfax,semail from supplierinfo ");
        //    strSql.Append(" where sid=@sid");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@sid", SqlDbType.Int,4)
        //    };
        //    parameters[0].Value = sid;

        //    lcs.Model.supplierinfo model=new lcs.Model.supplierinfo();
        //    DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
        //    if(ds.Tables[0].Rows.Count>0)
        //    {
        //        return DataRowToModel(ds.Tables[0].Rows[0]);
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}


        ///// <summary>
        ///// 得到一个对象实体
        ///// </summary>
        //public lcs.Model.supplierinfo DataRowToModel(DataRow row)
        //{
        //    lcs.Model.supplierinfo model=new lcs.Model.supplierinfo();
        //    if (row != null)
        //    {
        //        if(row["sid"]!=null && row["sid"].ToString()!="")
        //        {
        //            model.sid=int.Parse(row["sid"].ToString());
        //        }
        //        if(row["sno"]!=null)
        //        {
        //            model.sno=row["sno"].ToString();
        //        }
        //        if(row["sname"]!=null)
        //        {
        //            model.sname=row["sname"].ToString();
        //        }
        //        if(row["sadd"]!=null)
        //        {
        //            model.sadd=row["sadd"].ToString();
        //        }
        //        if(row["slink"]!=null)
        //        {
        //            model.slink=row["slink"].ToString();
        //        }
        //        if(row["sphone"]!=null)
        //        {
        //            model.sphone=row["sphone"].ToString();
        //        }
        //        if(row["sfax"]!=null)
        //        {
        //            model.sfax=row["sfax"].ToString();
        //        }
        //        if(row["semail"]!=null)
        //        {
        //            model.semail=row["semail"].ToString();
        //        }
        //    }
        //    return model;
        //}

        ///// <summary>
        ///// 获得数据列表
        ///// </summary>
        //public DataSet GetList(string strWhere)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select sid,sno,sname,sadd,slink,sphone,sfax,semail ");
        //    strSql.Append(" FROM supplierinfo ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获得前几行数据
        ///// </summary>
        //public DataSet GetList(int Top,string strWhere,string filedOrder)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select ");
        //    if(Top>0)
        //    {
        //        strSql.Append(" top "+Top.ToString());
        //    }
        //    strSql.Append(" sid,sno,sname,sadd,slink,sphone,sfax,semail ");
        //    strSql.Append(" FROM supplierinfo ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    strSql.Append(" order by " + filedOrder);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///// <summary>
        ///// 获取记录总数
        ///// </summary>
        //public int GetRecordCount(string strWhere)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("select count(1) FROM supplierinfo ");
        //    if(strWhere.Trim()!="")
        //    {
        //        strSql.Append(" where "+strWhere);
        //    }
        //    object obj = DbHelperSQL.GetSingle(strSql.ToString());
        //    if (obj == null)
        //    {
        //        return 0;
        //    }
        //    else
        //    {
        //        return Convert.ToInt32(obj);
        //    }
        //}
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        //{
        //    StringBuilder strSql=new StringBuilder();
        //    strSql.Append("SELECT * FROM ( ");
        //    strSql.Append(" SELECT ROW_NUMBER() OVER (");
        //    if (!string.IsNullOrEmpty(orderby.Trim()))
        //    {
        //        strSql.Append("order by T." + orderby );
        //    }
        //    else
        //    {
        //        strSql.Append("order by T.sid desc");
        //    }
        //    strSql.Append(")AS Row, T.*  from supplierinfo T ");
        //    if (!string.IsNullOrEmpty(strWhere.Trim()))
        //    {
        //        strSql.Append(" WHERE " + strWhere);
        //    }
        //    strSql.Append(" ) TT");
        //    strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
        //    return DbHelperSQL.Query(strSql.ToString());
        //}

        ///*
        ///// <summary>
        ///// 分页获取数据列表
        ///// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@tblName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@fldName", SqlDbType.VarChar, 255),
        //            new SqlParameter("@PageSize", SqlDbType.Int),
        //            new SqlParameter("@PageIndex", SqlDbType.Int),
        //            new SqlParameter("@IsReCount", SqlDbType.Bit),
        //            new SqlParameter("@OrderType", SqlDbType.Bit),
        //            new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
        //            };
        //    parameters[0].Value = "supplierinfo";
        //    parameters[1].Value = "sid";
        //    parameters[2].Value = PageSize;
        //    parameters[3].Value = PageIndex;
        //    parameters[4].Value = 0;
        //    parameters[5].Value = 0;
        //    parameters[6].Value = strWhere;	
        //    return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        //}*/

		#endregion  BasicMethod
		#region  ExtensionMethod
        /// <summary>
        /// 是否存在该记录,通过供应商和联系人来确定
        /// </summary>
        public bool Exists(string sname, string slink)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from supplierinfo");
            strSql.Append(" where sname=@sname and slink=@slink ");
            SqlParameter[] parameters = {
                    new SqlParameter("@sname", SqlDbType.NVarChar,30),
                    new SqlParameter("@slink", SqlDbType.NVarChar,10)
            };
            parameters[0].Value = sname;
            parameters[1].Value = slink;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 是否存在该记录,通过供应商名称来确定
        /// </summary>
        public bool ExistsByName(string sname)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from supplierinfo");
            strSql.Append(" where sname=@sname  ");
            SqlParameter[] parameters = {
                    new SqlParameter("@sname", SqlDbType.NVarChar,30)       
            };
            parameters[0].Value = sname;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 通过名字找到供应商ＩＤ
        /// </summary>
        /// <param name="sname"></param>
        /// <returns></returns>
        public int GetIDByName(string sname)
        {
            int sid = 0;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select sid from supplierinfo");
            strSql.Append(" where sname=@sname  ");
            SqlParameter[] parameters = {
                    new SqlParameter("@sname", SqlDbType.NVarChar,30)       
            };
            parameters[0].Value = sname;

            object o= DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (o != null)
            {
                sid = int.Parse(o.ToString());

            }
            return sid;
        }
		#endregion  ExtensionMethod
	}
}

